<template>
  <div class="shoplogo-content">
      <div class="headerimg">
          <img :src='shoplogo?shoplogo:noimg' class="headimg" @click="upimg">
      </div>
          <p class="tit">点击logo修改</p>
          <div class="setbtn" @click="Suk_savenotice">确认修改</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
        noimg:require('@/assets/img/none.png'),
        shoplogo:''
    };
  },
  beforeCreate: function() {
    //创建前
  },
  created: function() {
    //创建后
  },
  beforeMount: function() {
    //挂载前
  },
  mounted: function() {
    //挂载后
  },
  beforeUpdate: function() {
    //更新前
  },
  update: function() {
    //更新后
  },
  methods: {
    Suk_savenotice() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      var Sukdata = {
//      id: localStorage.getItem("storeid"),
				userid: localStorage.getItem("userid"),
        logo: that.shoplogo
      };
      console.log(Sukdata);
      that.axios
        .post(
          that.baseUrl + "/dining/updateImages",
          that.Qs.stringify(Sukdata),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          }
        )
        .then(function(res) {
          if (res.data.meta.code == -1) {
//            console.log(res.data);
              that.$toast.success({
                message: "商家不存在！"
              });
            } else if (res.data.meta.code == 1) {
            	that.$toast.success({
                message: "修改成功！"
              });
              that.$router.go(-1)
            }else if (res.data.meta.code == -2) {
            	that.$toast.success({
                message: "修改失败！"
              });
          }
        });
    },
    upimg(){
      // this.showzimg = 1
      // this.zimg = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547882174477&di=31b5bba04f4da5d3f4126ff93f4e85e7&imgtype=0&src=http%3A%2F%2Fthumb210.jfcdns.com%2Fn131929c23812%2F16f5c01f7c1049c3.jpeg"
      let that = this;
      dsBridge.call("uploadImg", 10);
      dsBridge.register("addImgCallback", function(data) {
        that.shoplogo = data
        // alert(that.zimg)
        // let str = JSON.parse(data)
        // that.$toast.loading({
        //   message: "加载中..."
        // });
        // alert("12132")
        var Sukdata = {
          zurl: data
        };
        console.log(Sukdata);
        that.axios
          .post(that.baseUrl + "/store/storeZheng", that.Qs.stringify(Sukdata), {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          })
          .then(function(res) {
            if (res.request.status === 200) {
              if (res.data.meta.code == 200) {
                alert(123);
                that.showzimg = 1
                // alert(res.data)
                // alert(that.zimg)
                // that.$toast.clear();
              } else if (res.data.meta.code == 501) {
              }
            }
          });
      });
    }
  }
};
</script>
<style lang='scss' scoped>
.shoplogo-content{
    font-size: 0.3rem;
}
.headerimg{
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto
}
.headimg{
    width: 100%;
    height: 100%;
}
.tit{
    text-align: center;
    font-size: 0.4rem;
    color: #fda229
}
.setbtn{
    width: 90%;
    background: #fda229;
    height: 1rem;
    line-height: 1rem;
    text-align: center;
    color: #fff;
    margin: 0 auto;
    border-radius: 0.5rem;
    margin-top: 2rem;
}
</style>